FUNCTION wage_pastmayor(tin,imunin,ieduin,ipastin)

  USE commonvars
  IMPLICIT NONE

  INTEGER, INTENT(IN) :: tin,imunin,ieduin,ipastin
  REAL(8)             :: wage_pastmayor
  REAL(8)             :: aud,aud_steal,pop,ln_pop
  INTEGER             :: imun_ch

  aud = 0d0
  aud_steal = 0d0

  IF(imunin == 2) imun_ch = 1
  IF(imunin == 3) imun_ch = 2
  IF(imunin == 1) imun_ch = 3

  IF(ipastin ==2) aud = 1d0
  IF(ipastin ==3) aud_steal = 1d0

  pop = popsize(imunin)
  ln_pop = LOG(pop)

  !If we use log wages in the estimation in stata
!!$  wage_pastmayor = EXP(alphaw(1) + alphaw(2)*DBLE(ieduin) + alphaw(3)*DBLE(tin) + alphaw(4)*DBLE(tin)**2d0 + alphaw(4 + imun_ch))/norm
  !The coefficients are estimated using wages/norm; we don't need to divide by the norm again
!!$  IF (imun_ch <= 2) THEN
!!$     wage_pastmayor = EXP(alphaw(1) + alphaw(2)*DBLE(ieduin) + alphaw(3)*DBLE(tin) + alphaw(4)*DBLE(tin)**2d0 + alphaw(5)*aud + alphaw(6)*aud_steal + alphaw(6 + imun_ch))
!!$  ELSE
!!$     wage_pastmayor = EXP(alphaw(1) + alphaw(2)*DBLE(ieduin) + alphaw(3)*DBLE(tin) + alphaw(4)*DBLE(tin)**2d0 + alphaw(5)*aud + alphaw(6)*aud_steal)
!!$  END IF
!!$  IF (wage_pastmayor <= 0d0) wage_pastmayor = small_no

  !If we use wages in levels in the estimation in stata
!!$  wage_pastmayor = alphaw(1) + alphaw(2)*DBLE(ieduin) + alphaw(3)*DBLE(tin) + alphaw(4)*DBLE(tin)**2d0 + alphaw(5)*aud*ln_pop + alphaw(6)*aud_steal*ln_pop + alphaw(7)*pop  + alphaw(8)*pop**2d0)
  IF (imun_ch <= 2) THEN
     wage_pastmayor = alphaw(1) + alphaw(2)*DBLE(ieduin) + alphaw(3)*DBLE(tin) + alphaw(4)*DBLE(tin)**2d0 + alphaw(5)*aud + alphaw(6)*aud_steal + alphaw(6 + imun_ch)
  ELSE
     wage_pastmayor = alphaw(1) + alphaw(2)*DBLE(ieduin) + alphaw(3)*DBLE(tin) + alphaw(4)*DBLE(tin)**2d0 + alphaw(5)*aud + alphaw(6)*aud_steal
  END IF

  IF (wage_pastmayor <= 0d0) wage_pastmayor = small_no

END FUNCTION wage_pastmayor
